//获取应用实例
import { $wuxSelect } from 'weapp/index';
import { buildTree } from "../../../utils/common";

const app = getApp();
const common = require('./../../../utils/common.js');
Page({
    data: {
        now_page: 0,
        list_total: 0,
        template_list: [],
        keywords: '',
        limit: 20,
        nav_list: [],
        active_nav_index: 0,
        tab_value: null,
        value3:'',//选择的季节筛选
        // 筛选
        year: [],
        yearArray: [],
        is_show_shade: 0,
        cate_show_data: [],
        cate_all_data: [],
        cata_list:[],
        sel_index_arr: [0, 0, 0],
        choose_index_arr: [],
        choose_id_arr: [],
        choose_id_arr_list: [],
        choose_cate_name: [],
        data_type_list: [
            {id: 1, name: '全部', value: 0},
            {id: 2, name: '正品', value: 1},
            {id: 3, name: '白批', value: 2},
        ],
        data_type_name: '',
        data_type_value: 0,
        // 切换
        search_or_filter: 1,
        filterShow: false, // 搜索弹框
        formData: {
          productNo: "",
          extensionCode: "",
          designerIds: [],
          designerName: "",
          designerIdsAll: [],
          categoryIdList: []
        },
        showSelector: false,
        selectorOptions: [],
        isMultiple: false,
        designerList: []
    },
    onLoad: function (options) {
        // 设置标题
        wx.setNavigationBarTitle({
            title: '款式列表'
        });
        // 生成年份
        this.generateYearArray();
        // 设置参数
        if (options.template_no != undefined) {
            this.setData({
                keywords: options.template_no != undefined ? options.template_no : '',
            })
        }
        if (options.tab_value != undefined) {
            this.setData({
                tab_value: options.tab_value != undefined ? options.tab_value : 'all'
            })
        }
        // 获取tab列表
        this.get_tab_list();
        // 获取分类
        // this.get_cate_list();
    },

    // 每次显示时
    onShow() {
        var __this = this;
        if (!app.check_is_login(false, true)) {
            // 显示登录
            wx.showModal({
                title: '提示',
                content: '请登录后再操作',
                showCancel: false,
                complete() {
                    // 获取tab列表
                    __this.get_tab_list();
                }
            });
        }
    },
    onClick3() {
      $wuxSelect('#foo-select3').open({
        value: this.data.value3,
        multiple: true,
        toolbar: {
          title: '季节',
          confirmText: '确定',
        },
        options: [
          {
            title: '春',
            value: '春',
          },
          {
            title: '夏',
            value: '夏',
          },
          {
            title: '秋',
            value: '秋',
          },
          {
            title: '冬',
            value: '冬',
          },
        ],
        onChange: (value, index, options) => {
          console.log('onChange', value, index, options)
          this.setData({
            // value3: value,
            title3: index.map((n) => options[n].title),
          })
        },
        onConfirm: (value, index, options) => {
          this.setData({
            value3: value,
            title3: index.map((n) => options[n].title),
          })
          this.onPullDownRefresh();
        },
      })
    },
    DeleteJijie(e){
      var index = e.currentTarget.dataset.index;
      this.data.value3.splice(index, 1);
      this.setData({
          value3: this.data.value3,
      })
      // 刷新
      this.onPullDownRefresh();
    },
    template_purchase: (e) => {
        let {template_id} = e.currentTarget.dataset;
        wx.navigateTo({
            url: '/pages/material/index?template_id=' + template_id,
        })
    },
    // 页面触底时执行
    onReachBottom: function () {
        this.get_template_list();
    },

    // 监听下拉[刷新]
    onPullDownRefresh: function () {
        this.setData({
            template_list: [],
            list_total: 0,
            now_page: 0,
        });
        // 获取列表
        this.get_template_list();
        // 停止下拉
        setTimeout(() => {
            wx.stopPullDownRefresh();
        }, 1000)
    },

    // 获取tab列表
    get_tab_list: function () {
      // 发起请求
      const nav_list = [
        {
          count: 0,
          status: "全部",
          type: "warning",
          value: "all",
        }
      ] 
      this.setData({
          nav_list: nav_list
      });
      // 自动跳转到对应tab
      if (this.data.tab_value != null) {
          var s_index = nav_list.findIndex(obj => obj.value == this.data.tab_value);
          if (s_index > -1) {
              this.setData({
                  active_nav_index: s_index
              })
          }
      }
      // 如果是谷冬冬则默认显示外套分类
      if (wx.getStorageSync('user_id') == 53 || wx.getStorageSync('user_id') == 50) {
          this.setData({
              choose_id_arr: [[262, 0, 0]],
              choose_index_arr: [[0, 0, 0]],
              choose_cate_name: ["外套 - 全部 - 全部"],
          });
      }
      // 获取款式列表
      this.get_template_list();
      // 获取分类
      this.get_cate_list();
      
  },

    // get_tab_list_old: function () {
    //     // 发起请求
    //     var result = app.request_api('admin/template/getTabs', {}, true, 'GET');
    //     result.then(res => {
    //         this.setData({
    //             nav_list: res
    //         });
    //         // 自动跳转到对应tab
    //         if (this.data.tab_value != null) {
    //             var s_index = this.data.nav_list.findIndex(obj => obj.value == this.data.tab_value);
    //             if (s_index > -1) {
    //                 this.setData({
    //                     active_nav_index: s_index
    //                 })
    //             }
    //         }
    //         // 如果是谷冬冬则默认显示外套分类
    //         if (wx.getStorageSync('user_id') == 53 || wx.getStorageSync('user_id') == 50) {
    //             this.setData({
    //                 choose_id_arr: [[262, 0, 0]],
    //                 choose_index_arr: [[0, 0, 0]],
    //                 choose_cate_name: ["外套 - 全部 - 全部"],
    //             });
    //         }
    //         // 获取款式列表
    //         this.get_template_list();
    //         // 获取分类
    //         this.get_cate_list();
    //     });
    // },

    // 切换展示搜索或者筛选
    search_filter_change: function (events) {
        // this.setData({
        //     search_or_filter: this.data.search_or_filter == 1 ? 2 : 1
        // })
        this.setData({
          filterShow: true
        })
    },

    // 点击菜单
    change_nav: function (events) {
        var index = events.currentTarget.dataset.index;
        this.setData({
            active_nav_index: index,
            template_list: [],
            list_total: 0,
            now_page: 0,
        });
        // 重新获取数据
        this.get_template_list();
    },

    // 获取款式列表
    get_template_list: function (is_search = 0) {
        var __this = this;
        // 验证
        if ((this.data.template_list.length >= this.data.list_total) && this.data.now_page > 0) {
            return false;
        }
        let selectParameter = {"sort":"11","keyWord":__this.data.keywords}
        const choose_index_arr = this.data.choose_index_arr
        const cate_all_data = this.data.cate_all_data
        let categoryIdList = []
        const choose_id_arr_list = this.data.choose_id_arr_list
        choose_id_arr_list.forEach(item => {
          item.forEach(item2 => {
              console.log('item2item2item2item2item2', item2)
            const ids = item2.split(',')
            categoryIdList = categoryIdList.concat(ids)
          })
        })
        selectParameter = {
          ...selectParameter,
          ...this.data.formData,
          categoryIdList
        }
        console.log(this.data.value3);
        // 组装条件
        let req_data = {
            current: this.data.now_page + 1,
            needPage: true,
            size: __this.data.limit,
            orderBy:"",
            parame:[],
            selectParameter:selectParameter,
            // "params[status]": __this.data.nav_list[__this.data.active_nav_index].value,
        };
        // 年份
        // if (this.data.year.length > 0) {
        //     req_data.year = this.data.year;
        // }
        // // 分类
        // let category1 = [];
        // let category2 = [];
        // let category3 = [];
        // if (this.data.choose_id_arr.length > 0) {
        //     this.data.choose_id_arr.forEach(function (item, index) {
        //         category1.push(item[0]);
        //         category2.push(item[1]);
        //         category3.push(item[2]);
        //     });
        // }
        // req_data.category1 = category1;
        // req_data.category2 = category2;
        // req_data.category3 = category3;
        // // 如果有选择分类则人员类型条件失效
        // if (category1.length > 0) {
        //     req_data.search = [{
        //         field: 'data_type',
        //         val: [1, 2, 3, 4, 5, 6, 7],
        //         operator: false
        //     }];
        // }
        // // 如果有选择分类则人员类型条件失效
        // if (this.data.value3.length > 0) {
        //   req_data.search = [{
        //       field: 'season',
        //       val: this.data.value3,
        //       operator: '123'
        //   }];
        // }
        // 发起请求
        var result = common.request_api('/api/bamboo/pdSpu/queryProductListPage', req_data, true);
        result.then(res => {
            if (is_search == 1) {
                this.setData({
                    template_list: [],
                    list_total: 0,
                    now_page: 0,
                })
            }
            if (res.data.records.length > 0) {
              res.data.records.forEach(function (item, index, array) {
                if (item.classificationText) {
                  let classificationTextArr = item.classificationText.split('/')
                  array[index]['cate_name1'] = classificationTextArr[0];
                  array[index]['cate_name2'] = classificationTextArr[1];
                  array[index]['cate_name3'] = classificationTextArr[2];
                }
              })
            }
            // res.list.forEach((v, k) => {
            //     v.num = v.color_list.reduce((accumulator, currentValue) => {
            //         return accumulator + currentValue.quantity
            //     }, 0)
            //     v.is_show_plan = true;
            //     if (v.batch_list.length > 0) {
            //         v.batch_list.map((batch_item) => {
            //             batch_item.diy_style = '';
            //             batch_item.diy_height = 55;
            //             if(batch_item.sku_list!==undefined){
            //               if (batch_item.sku_list.length > 0) {
            //                 let now_len = batch_item.sku_list.length;
            //                 batch_item.diy_style = 'height:calc('+ now_len * 55 +'vmin / 7.5);line-height: calc('+  now_len * 55 +'vmin / 7.5);';
            //                 batch_item.diy_height = 55 * now_len;
            //               }
            //             }else{
            //                 console.log('batch_item',batch_item)
            //             }
            //
            //             return batch_item;
            //         });
            //     }
            //     if (v.goods_purchase_list.length > 0) {
            //       v.goods_purchase_list.map((batch_item) => {
            //           batch_item.diy_style = '';
            //           batch_item.diy_height = 55;
            //           if(batch_item.sku_list!==undefined){
            //             if (batch_item.sku_list.length > 0) {
            //               let now_len = batch_item.sku_list.length;
            //               batch_item.diy_style = 'height:calc('+ now_len * 55 +'vmin / 7.5);line-height: calc('+  now_len * 55 +'vmin / 7.5);';
            //               batch_item.diy_height = 55 * now_len;
            //             }
            //           }else{
            //               console.log('batch_item',batch_item)
            //           }
            //           return batch_item;
            //       });
            //   }
            // })
            this.setData({
                template_list: this.data.template_list.concat(res.data.records),
                list_total: res.total,
                now_page: this.data.now_page + 1
            });
        });
    },

    // 搜索
    GoSearch: function (events) {
        var keywords = events.detail.value.trim();
        this.setData({
            keywords: keywords,
            template_list: [],
            now_page: 0,
            list_total: 0,
        });
        this.get_template_list(1);
    },

    // 创建款式
    template_add: function (events) {
        var __this = this;
        // 跳转到创建款式页面
        wx.navigateTo({
            url: '/alpha/pages/alpha_template_add/index?template_id=0', 
            events: {
                // 当添加完成时重新请求数据
                changeData: function (data) {
                    __this.setData({
                        keywords: '',
                        template_list: [],
                        now_page: 0,
                        list_total: 0,
                    });
                    __this.get_template_list();
                }
            }
        });
    },

    // 编辑款式
    template_update: function (events) {
        var index = events.currentTarget.dataset.index;
        var __this = this;
        // 跳转
        wx.navigateTo({
            url: '/alpha/pages/alpha_template_add/index?productId=' + __this.data.template_list[index].id,
            events: {
                // 当修改完成时
                changeData: function (data) {

                }
            }
        });
    },

    // 跳转到详情页面
    template_detail: function (events) {
        var index = events.currentTarget.dataset.index;
        var __this = this;
        // 跳转
        wx.navigateTo({
            url: '/alpha/pages/alpha_template_detail/template_detail?template_id=' + __this.data.template_list[index].id,
        });
    },

    // 关闭生产
    template_close: function (events) {
        var index = events.currentTarget.dataset.index;
        var __this = this;
        // 确认提示
        wx.showModal({
            title: '提示',
            content: '您确定要关闭生产吗',
            success(res) {
                if (res.confirm) {
                    __this.template_close_request(index);
                }
            },
        });
    },

    // 关闭生产请求
    template_close_request: function (index) {
        var __this = this;
        var template_id = __this.data.template_list[index].template_id;
        var result = app.request_api('admin/template/closeTemplate', {
            id: template_id
        }, true);
        result.then(res => {
            wx.showToast({
                title: '已关闭生产',
                icon: 'none',
                duration: 2000,
            });
            // 将此数据从列表删除
            __this.data.template_list.splice(index, 1);
            __this.setData({
                template_list: __this.data.template_list
            });
        });
    },

    // 删除
    template_delete: function (events) {
        var index = events.currentTarget.dataset.index;
        var __this = this;
        // 确认提示
        wx.showModal({
            title: '提示',
            content: '您确定要删除此款式吗',
            success(res) {
                if (res.confirm) {
                    __this.template_delete_request(index);
                }
            },
        });
    },

    // 删除款式请求
    template_delete_request: function (index) {
        var __this = this;
        var template_id = __this.data.template_list[index].template_id;
        var result = app.request_api('admin/template/del', {
            ids: [template_id]
        }, true);
        result.then(res => {
            wx.showToast({
                title: '删除成功',
                icon: 'none',
                duration: 2000,
            });
            // 将此数据从列表删除
            __this.data.template_list.splice(index, 1);
            __this.setData({
                template_list: __this.data.template_list
            });
        });
    },

    // 确认生产
    template_product: function (events) {
        var index = events.currentTarget.dataset.index;
        var __this = this;
        // 确认提示
        wx.showModal({
            title: '提示',
            content: '您确定要开始生产吗',
            success(res) {
                if (res.confirm) {
                    __this.template_product_request(index);
                }
            },
        });
    },

    // 确认生产请求
    template_product_request: function (index) {
        var __this = this;
        var template_id = __this.data.template_list[index].template_id;
        var result = app.request_api('admin/template/postConfirmProduct', {
            template_id: template_id
        }, true);
        result.then(res => {
            wx.showToast({
                title: '已开始生产',
                icon: 'none',
                duration: 2000,
            });
            // 修改状态
            __this.data.template_list[index].status.value = 3;
            __this.setData({
                template_list: __this.data.template_list
            });
        });
    },

    // 预览图片
    PreviewImg: function (events) {
        var pic_arr = events.currentTarget.dataset.pic;
        // 调用
        wx.previewImage({
            current: pic_arr[0], // 当前显示图片的http链接
            urls: pic_arr // 需要预览的图片http链接列表
        })
    },

    // 生成年份
    generateYearArray: function () {
        var currentYear = new Date().getFullYear();
        var pastYears = 7;
        var futureYears = 3;
        var yearArray = [];
        // 生成过去7年的年份
        for (var i = currentYear - pastYears; i <= currentYear; i++) {
            yearArray.push(i);
        }
        // 生成未来3年的年份
        for (var j = currentYear + 1; j <= currentYear + futureYears; j++) {
            yearArray.push(j);
        }
        var currentIndex = pastYears;
        // 更新数据
        this.setData({
            yearArray: yearArray,
            currentIndex: currentIndex
        });
    },

    // 年份改变时
    yearChange: function (event) {
        var selectedYear = this.data.yearArray[event.detail.value];
        // 验证是否在数组中
        if (this.data.year.findIndex(obj => obj === selectedYear) > -1) {
            wx.showToast({
                title: '已选择过此年份',
                icon: 'none',
                duration: 1500,
            });
            return false;
        }
        this.data.year.push(selectedYear)
        this.setData({
            year: this.data.year,
        });
        // 刷新
        this.onPullDownRefresh();
    },
    newYearChange: function (event) {
      var selectedYear = this.data.yearArray[event.detail.value];
      // 验证是否在数组中
      if (this.data.formData.year && this.data.formData.year.findIndex(obj => obj === selectedYear) > -1) {
          wx.showToast({
              title: '已选择过此年份',
              icon: 'none',
              duration: 1500,
          });
          return false;
      }
      console.log(selectedYear,'selectedYear');
      this.data.year.push(selectedYear)
      this.setData({
          year: this.data.year,
      });
    },
    // 选择类型时
    dataTypeChage: function (e) {
        this.setData({
            data_type_name: this.data.data_type_list[e.detail.value].name,
            data_type_value: this.data.data_type_list[e.detail.value].value,
        });
        // 刷新
        this.onPullDownRefresh();
    },

    // 获取分类
    get_cate_list: function () {
        // 发起请求
        var result = common.request_api('/api/bamboo/pdCategory/listAll', {}, false, 'GET');
        result.then(res => {
            const tree = buildTree(res.data)
            console.log(tree,'tree');
            if (tree.length > 0) {
                tree.forEach(function (item, index) {
                    // 往子项里追加全部

                    // 二级的全部，塞入二级所有id
                    const id = item.children.map(p => p.id).join(',')
                    item.children.unshift({
                        id: id,
                        cnName: '全部',
                        children: [],
                        pp_id:0
                    });

                    // 收集全部下的全部 == 当前一级分类下面的所有三级分类集合
                    let allIds = [];
                    item.children.forEach((item2,index2)=>{
                        const id = item2.children.map(p => p.id);
                        allIds = allIds.concat(id);
                    });
                   
                    item.children.forEach((item2,index2)=>{
                         // 当前二级分类所有id
                         const id = item2.children.map(p => p.id)

                         let setId = [];
                        if(item2.cnName == '全部'){
                            setId = allIds
                        }else{
                            setId = id
                        }
                       
                        item2.children.unshift({
                            id: setId.join(","),
                            cnName: '全部',
                            pp_id:0
                        });
                    })

                    // if (tree[index].children && tree[index].children.length > 0) {
                    //   const id = tree[index].children.map(p => p.id).join(',')
                    //   tree[index].children.unshift({
                    //     id: id,
                    //     cnName: '全部',
                    //     children: [],
                    //     pp_id:0
                    //   });
                    // } else {
                    //   tree[index].children.unshift({
                    //     id: '0',
                    //     cnName: '全部',
                    //     children: [],
                    //     pp_id:0
                    //   });
                    // }
                    // let chiId = []
                    // item.children.forEach((item2, index2) => {
                    //   const is_chiId = item2.children.map( p => p.id)
                    //   chiId = chiId.concat(is_chiId)
                    // })
                    // tree[index].children.forEach(function (item2, index2) {
                    //     if (index2 === 0) {
                    //       const id = chiId.join(',')
                    //       tree[index].children[index2].children.unshift({
                    //         id: id ? id : '0',
                    //         cnName: '全部',
                    //         pp_id:tree[index].id
                    //       });
                    //     }
                    // });
                });
                this.setData({
                    cate_show_data: [tree, tree[0].children, tree[0].children[0].children],
                    cate_all_data: tree,
                    cata_list :res.data
                });
            }
        });
    },


// 分类值变化时
    CateValueChange: function (e) {
        var cate_show_data = this.data.cate_show_data;
        var choose_index_arr = e.detail.value;
        let choose_cate_name = ''
        let isIds = []
        choose_index_arr.forEach((item, index) => {
          const id = cate_show_data[index][item].id
          if (index !== choose_index_arr.length - 1) {
            choose_cate_name += cate_show_data[index][item].cnName + ' - '
          } else {
            choose_cate_name += cate_show_data[index][item].cnName
          }
          console.log('hjx',cate_show_data[index][item])
          isIds.push(cate_show_data[index][item].id)
        })
        let choose_id_arr_list = this.data.choose_id_arr_list || []
        let flag = this.data.choose_id_arr_list.find( i => JSON.stringify(i) === JSON.stringify(isIds))
        if (flag) {
          wx.showToast({
            title: '该分类条件已存在',
            icon: 'error',
            duration: 2000,
          });
          return
        }
        choose_id_arr_list.push(isIds)
        // var choose_cate_name = cate_show_data[0][choose_index_arr[0]].cnName + ' - ' + cate_show_data[1][choose_index_arr[1]].cnName + ' - ' + cate_show_data[2][choose_index_arr[2]].cnName;
        // 更新值
        this.data.choose_id_arr.push(isIds);
        this.data.choose_cate_name.push(choose_cate_name);
        this.data.choose_index_arr.push(choose_index_arr);
        let arr = new Array()
        for (const item of this.data.choose_id_arr) {
            if (item[0] == 0 && item[1] == 0 && item[2] == 0) {
                arr = new Array()
                break;
            }
            if (item[0] != 0 && item[1] != 0 && item[2] != 0) {
                arr.push(item[2])
            }
            if (item[0] != 0 && item[1] == 0  && item[2] == 0) {
                for (const cate_item of this.data.cate_all_data) {
                    if (cate_item.id != item[0]) {
                        continue;
                    }
                    for (const son of cate_item.children) {
                        for (const da of son.children) {
                            if (da.id > 0) {
                                arr.push(da.id)
                            }
                        }
                    }
                }
            }
            if (item[0] != 0 && item[1] != 0  && item[2] == 0) {
                for (const cate_item of this.data.cate_all_data) {
                    if (cate_item.id != item[0]) {
                        continue;
                    }
                    for (const son of cate_item.children) {
                        if (son.id != item[1]) {
                            continue;
                        }
                        for (const da of son.children) {
                            if (da.id > 0) {
                                arr.push(da.id)
                            }
                        }
                    }
                }
            }
        }
        this.setData({
            choose_id_arr: arr,
            choose_index_arr: this.data.choose_index_arr,
            choose_cate_name: this.data.choose_cate_name,
            choose_id_arr_list
        });
        // 刷新
        this.onPullDownRefresh();
    },

    // 分类列变化时
    CateColumnChange: function (e) {
        var cate_all_data = this.data.cate_all_data;
        var cate_show_data = this.data.cate_show_data;
        var sel_index_arr = this.data.sel_index_arr;
        var index = e.detail.value;
        if (e.detail.column == 0) {
            // 一级分类改变时
            this.data.cate_show_data[1] = cate_all_data[index].children;
            this.data.cate_show_data[2] = cate_all_data[index].children[0].children;
            sel_index_arr = [index, 0, 0];
        }
        if (e.detail.column == 1) {
            // 二级分类改变时
            this.data.cate_show_data[2] = cate_show_data[1][index].children;
            sel_index_arr[1] = index;
            sel_index_arr[2] = 0;
        }
        if (e.detail.column == 2) {
            // 三级分类改变时
            sel_index_arr[2] = index;
        }
        // 重新渲染
        this.setData({
            cate_show_data: this.data.cate_show_data,
            sel_index_arr: sel_index_arr
        });
    },

    // 删除年份
    DeleteYear: function (e) {
        var index = e.currentTarget.dataset.index;
        // 删除对应年份
        this.data.year.splice(index, 1);
        this.setData({
            year: this.data.year,
        })
        // 刷新
        this.onPullDownRefresh();
    },

    // 删除分类
    DeleteCategory: function (e) {
        var index = e.currentTarget.dataset.index;
        const choose_id_arr_list = this.data.choose_id_arr_list
        choose_id_arr_list.splice(index, 1);
        this.data.choose_id_arr.splice(index, 1);
        this.data.choose_index_arr.splice(index, 1);
        this.data.choose_cate_name.splice(index, 1);
        this.setData({
            choose_id_arr: this.data.choose_id_arr,
            choose_index_arr: this.data.choose_index_arr,
            choose_cate_name: this.data.choose_cate_name,
            choose_id_arr_list
        })
        // 刷新
        this.onPullDownRefresh();
    },

    // 删除品牌
    DeleteType: function () {
        this.setData({
            data_type_value: 0,
            data_type_name: '',
        })
        // 刷新
        this.onPullDownRefresh();
    },

    // 展示计划
    showPlan: function (e) {
        var index = e.currentTarget.dataset.index;
        if (this.data.template_list[index].is_show_plan) {
            this.data.template_list[index].is_show_plan = false;
        } else {
            this.data.template_list[index].is_show_plan = true;
        }
        this.setData({
            template_list: this.data.template_list
        })
    },

    // 展示全
    showFullText: function (e) {
        let text = e.currentTarget.dataset.text;
        if (text != null && text != '') {
            wx.showToast({
                'title': text,
                icon: 'none',
                duration: 2000,
            });
        }
    },
    searchChange(events) {
      const keywords = events.detail.trim();
      const formData = this.data.formData
      const name = events.currentTarget.dataset.name
      formData[name] = keywords
      this.setData({
        formData
      });
    },
    closeFilter() {
      const formData = {
        productNo: "",
        extensionCode: "",
        designerIds: [],
        designerName: "",
        designerIdsAll: [],
        categoryIdList: []
      }
      this.setData({
        formData
      })
    },
    saveFilter() {
      this.setData({
        filterShow: false,
        now_page: 0
      })
      this.get_template_list(1)
    },
    onCloseFilterShow() {
      this.setData({
        filterShow: false
      });
    },
    handleClose(e) {
      const name = e.target.dataset.name
      this.setData({
        [name]: false
      })
    },
    // 物料选择
    handleSelect(event) {
      const detail = event.detail
      console.log(detail,'detail');
      const designerIds = detail.map(i => i.value)
      const designerName = detail.map(i => i.label).join(',')
      const formData = this.data.formData
      formData.designerIds = designerIds || []
      formData.designerIdsAll = detail || []
      formData.designerName = designerName || ''
      this.setData({
        formData
      })
    },
    async handleDesigner() {
      if (!(this.data.designerList && this.data.designerList.length > 0)){
      const result = await common.request_api('/api/ums/positionDuty/queryDropUserByDutyCode/designer', {}, false, 'GET');
      console.log(result);
        if (result.code == 200) {
          const data = result.data || []
          this.setData({
            designerList: data
          })
        }
      }
      const yearArray =this.data.yearArray
      const selectorOptions = this.data.designerList
      this.setData({
        showSelector: true,
        isMultiple: true,
        selectorOptions
      })
    }
})
